﻿using BLL;
using Models;
using Models.webReq;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using webui.Models;

namespace webui.Areas.Admin.Controllers
{
    public class CarController : Controller
    {
        public Car_carInfoBLL carbll = new Car_carInfoBLL();


        //打开主页
        [SkipPemission]
        public ActionResult Index()
        {
            ViewBag.url =     ConfigurationSettings.AppSettings["httpip"];
            return View();
        }

        [AjaxRequest]
        public ActionResult CarList(CarCondition carcondtion)
        {
            int pageIndex = carcondtion.page == 0 ? 1 : carcondtion.page;
            int pageSize = carcondtion.rows == 0 ? 5 : carcondtion.rows;
            PageModel page = new PageModel()
            {
                PageIndex = pageIndex,
                PageSize = pageSize,
                PageCount = 0
            };
            
             PageModel pg = new PageModel() { PageIndex = carcondtion.page, PageSize = carcondtion.rows };
            List<Car_carInfo> list = new List<Car_carInfo>();
            List<IConditionalModel> liswhere = new List<IConditionalModel>();
            if (carcondtion.sellState!= -1)
            {
                liswhere.Add(new ConditionalModel() { FieldName = "sellState", ConditionalType = ConditionalType.Equal, FieldValue = carcondtion.sellState.ToString() });
            }
            if (!string.IsNullOrEmpty(carcondtion.brandName))
            {
                liswhere.Add(new ConditionalModel() { FieldName = "brandName", ConditionalType = ConditionalType.Like, FieldValue = carcondtion.brandName });
            }
            if (!string.IsNullOrEmpty(carcondtion.xingHao))
            {
                liswhere.Add(new ConditionalModel() { FieldName = "xingHao", ConditionalType = ConditionalType.Like, FieldValue = carcondtion.xingHao });
            }
            if (!string.IsNullOrEmpty(carcondtion.speedAssembly))
            {
                liswhere.Add(new ConditionalModel() { FieldName = "speedAssembly", ConditionalType = ConditionalType.Like, FieldValue = carcondtion.speedAssembly });
            }
            if (carcondtion.shopid!=0)
            {
                liswhere.Add(new ConditionalModel() { FieldName = "shopid", ConditionalType = ConditionalType.Equal, FieldValue = carcondtion.shopid.ToString() });
            }
            if (!string.IsNullOrEmpty(carcondtion.CloseBegin))
            {
                liswhere.Add(new ConditionalModel() { FieldName = "CloseTime", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = carcondtion.CloseBegin });
            }
            if (!string.IsNullOrEmpty(carcondtion.CloseEnd))
            {
                liswhere.Add(new ConditionalModel() { FieldName = "CloseTime", ConditionalType = ConditionalType.LessThanOrEqual, FieldValue = carcondtion.CloseEnd });
            }

            list = carbll.GetPageList(liswhere, pg,u=> u.id,OrderByType.Desc);

            return Json(new DataGridModel() { rows = list, total = pg.PageCount });
         
        }


        /// <summary>
        /// 显示 新增新闻列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [AjaxRequest]
        [SkipPemission]
        public ActionResult Addcar()
        {
            return PartialView("Addcar");
        }




    }
}